package com.sailors.common.task.provider.infra.design.common.util;

import lombok.SneakyThrows;

import java.lang.reflect.Constructor;

public class ObjectUtil {

    private ObjectUtil() {};

    @SneakyThrows
    public static <T> T obtain(Class<T> clazz) {
        // 2. 获取私有无参构造
        Constructor c = clazz.getDeclaredConstructor();
        // 3. 设置访问为可见
        c.setAccessible(true);
        // 4. 通过构造器创建实例对象
        return (T) c.newInstance();
    }
}
